<?php

/**
 * formularios actions.
 *
 * @package    seewaldinformatica.com.ar
 * @subpackage formularios
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class formulariosActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('default', 'module');
  }
  
  public function executeContacto(sfWebRequest $request)
  {
      $this->form = new ContactoForm();
      $this->datos = $request->getParameter('contacto');
//      $this->configuration = ConfigurationsQuery::create()->findOneByName('main_address');
      //print_r($this->datos);
      if ($request->isMethod('post'))
      {
          $this->form->bind($this->datos);
          if($this->form->isValid()){
              $body = "<h2>Mensaje enviado desde Albalandia.com.ar</h2>";
              $body.= "<div><strong>Nombre:</strong> ".$this->datos['nombre']."</div>";
              $body.= "<div><strong>Pais:</strong> ".$this->datos['pais']."</div>";
              $body.= "<div><strong>E-mail:</strong> ".$this->datos['email']."</div>";
              $body.= "<div><strong>Telefono:</strong> ".$this->datos['telefono']."</div>";
              $body.= "<div><strong>Consulta:</strong> ".$this->datos['consulta']."</div>";

                $message = $this->getMailer()->compose(
                  array('info@albalandia.com.ar' => 'Formulario de Contacto ~ Albalandia SRL'),
                  'walterseewald@gmail.com',
                  'Formulario de Contacto ~ Albalandia SRL',
                  $body
                );
                $message->setContentType("text/html");
                $message->setReplyTo(array($this->datos['email'] => $this->datos['nombre']));

                if($this->getMailer()->send($message)){
                    //$this->getUser()->setFlash('notice', 'Your message has been send successfully. Thank you.');
                    echo 'Your message has been send successfully. Thank you.';
                    $this->form = new ContactForm();
                }else{
                    //$this->getUser()->setFlash('error', 'The message has not been sending due to some errors.', false);
                    echo 'The message has not been sending due to some errors.';
                }
          }else{
              echo $this->form->getErrorSchema()->getMessage();
          }
      }
      return sfView::NONE;
  }
}
